package edu.sctu.jsoup.service;

import edu.sctu.jsoup.repo.ArticleRepo;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.IOException;

/**
 * Created by lenovo on 2017/10/10.
 */
@Service
public class ArticleService {
    @Autowired
    private ArticleRepo articleRepo;
    public void run(){
        try{
           Document document=Jsoup.connect("http://www.sctu.edu.cn").get();
            Elements elements=document.select("div.tab").first().select("li");
            for (Element element:elements){
                String puDate=elements.select("dl").first().text();
               String titel= elements.select("a").first().text();
                String url=elements.select("a").first().attr("href");
                System.out.println(puDate+" "+titel+" "+url);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
